package com.thread;

/**
 * Created by Sunny on 2016/4/14.
 */
public class SychronizedTest4 {

    public static void main(String[] args) {
        Object1 o = new Object1();
        ThreadA a = new ThreadA(o);
        ThreadB b = new ThreadB(o);
        a.start();
        b.start();
    }
}


class ThreadA extends Thread{

    private Object1 o;
    public ThreadA(Object1 o){
        this.o = o;
    }

    @Override
    public void run() {
        o.printA();
    }
}



class ThreadB extends Thread{

    private Object1 o;
    public ThreadB(Object1 o){
        this.o = o;
    }

    @Override
    public void run() {
        o.printB();
    }
}

class Object1{

    public synchronized  void printA(){
        System.out.println("pringA begin");
        boolean flag = true;
        while(flag){

        }
        System.out.println("pringA end");
    }

    public synchronized  void printB(){
        System.out.println("pringB begin");

        System.out.println("pringB end");
    }
}